<?php
//session_start();
/**
** $Author: serge $
** $Revision: 1.6 $
** $Date: 2006/08/11 15:51:31 $
** $Log: CalContact.php,v $
** Revision 1.6  2006/08/11 15:51:31  serge
** Preversion, juste avant la premiere phase de test.
**
*/
/****************************************************************
** Application : Nova
**
** Les buts de cet application sont de fournir un outils de partage
** de l'information pour le site membre "nova"
**
** Les auteurs :
** 		Design Web 			: Serge Peter
** 		Developpement PHP 	: Serge Peter
** 		Etudes 				: Sandrine Guihenneuc
**		Feuille de style	: Sandrine Guihenneuc
** Fichier CalContact.php :
** 		Ce fichier regroupe les fonctions liees au contacts
**
*****************************************************************/

/**
* @function treate_contacts
*
* @deal fonction globale de traitement des contacts
*
* @param  object  $db        	Instance d'une connexion DB
* @param  string  INDEX_FORM   Page php d index
* @param  string  $sevice_id 	Reference id du service, ici les contacts
*/
function treate_contacts($db,  $service_id)
{

/* check des droits */
if ($_SESSION['ponderation'] >=10) {

/* lecture des variable */
	if (isset($_GET["adm_id"]))
		$id = $_GET['adm_id'];
	else
		$id=0;
	
	if (isset($_GET["adm_action"]))
		$action = $_GET['adm_action'];
	else
		$action=0;


if (isset($_GET['cur_page'])) {
	$cur_page = $_GET['cur_page'];
}else{
	$cur_page = 1;
}
/* get filter */
if ( isset($_GET['filter']) ) {
	$filter = $_GET['filter'];
}else{
	$filter =0;
}

/* stockage dans des variables session des variables propre au filtrage */
if ( $_GET['filter'] == 0 ){
	$_SESSION['search_nom']  = "" ;
	$_SESSION['search_prenom']  = "" ;
	$_SESSION['search_societe']  = "" ;
	$_SESSION['search_contact_type_id']  = "";
	$_SESSION['search_where_clause']  = "" ;
} else {
	$search_nom = $_SESSION['search_nom'];
	$search_prenom = $_SESSION['search_prenom'];
	$search_societe = $_SESSION['search_societe'];
	$search_contact_type_id = $_SESSION['search_contact_type_id'];
	$search_where_clause = $_SESSION['search_where_clause'];
}

/* debug */
deb_echo ("search_nom : " . $_SESSION['search_nom']);
deb_echo ("search_contact_type_id : " . $_SESSION['search_contact_type_id']);

/* variable "globale" */
$table_name = TB . 'contacts';
$titre = "Contacts";
$shortname="contacts";

/*
** application du mode par defaut.
** le mode "action" est passe en parametre de l'url ...?action=SELECTION par example
*/
if (empty ($action))
	$action = 0;

/* travail en fonction des actions */
switch($action)
{
	case 0;   // Mode selection

		if ( $filter != 0 ){
			/********************************
			** FILTRAGE
			*********************************/

			/* formulaire de filtrage */
			$form = new HTML_QuickForm('filter_form', 'post', INDEX_FORM . "?adm_action=0&id=" . $service_id . "&sub_id=". $shortname . "&filter=2" );
			$form->addElement('text', 'search_societe', 'Societe', array('value' => $search_societe, 'size' => 40, 'maxlength' => 50));
			$form->addElement('text', 'search_nom', 'Nom', array('value' => $search_nom, 'size' => 40, 'maxlength' => 50));
			$form->addElement('text', 'search_prenom', 'Prenom', array('value' => $search_prenom, 'size' => 40, 'maxlength' => 60));
			$form->addElement('text', 'search_where_clause', 'Libre', array('value' => $search_where_clause, 'size' => 40, 'maxlength' => 60));

			$res1 = $db->getAssoc('SELECT * FROM ' . TB . 'contact_types');
			$form->addElement('select', 'search_contact_type_id', 'Type', $res1, 'id=id');

			$form->addElement('submit', 'bouton_effacer', 'Lancer');

			form_display($form, "Formulaire de filtrage", "forms", "100%");

			/* c'est quand l'utlisateur presse le bouton .... */
			if ($form->validate()) {  //form
				/* variables de filtrage =>session */
				$_SESSION['search_nom']  = $form->exportValue('search_nom') ;
				$_SESSION['search_prenom']  = $form->exportValue('search_prenom') ;
				$_SESSION['search_societe']  = $form->exportValue('search_societe');
				$_SESSION['search_contact_type_id']  = $form->exportValue('search_contact_type_id');
				$_SESSION['search_where_clause']  = $form->exportValue('search_where_clause');
			} // Form filtrage
		}

		/* construction de la clause where pour le filtrage	*/
		if ( $filter == 0){
			$filter_tmp_label=MSG_CONT_1;
			$filter_back_url="filter=1";
			$filter_img=IMG_CONT_1;
			$search_sql_where = "";
		}
		if ( $filter == 1 ){
			$filter_tmp_label=MSG_CONT_1;
			$filter_back_url="filter=0";
			$filter_img=IMG_CONT_2;

		}
		if ( $filter == 2 ) {
			$filter_tmp_label=MSG_CONT_2;
			$filter_back_url="filter=0";
			$filter_img=IMG_CONT_2;

			if ( $_SESSION['search_nom'] != "" ) {
				$search_sql_where=" and bl.nom like '%" . $_SESSION['search_nom']. "%'";
			}

			if ( $_SESSION['search_prenom'] != "" ) {
				$search_sql_where .=" and bl.prenom like '%" . $_SESSION['search_prenom']. "%'";
			}

			if ( $_SESSION['search_societe'] != "" ) {
				$search_sql_where .= " and bl.societe like '%" . $_SESSION['search_societe']. "%'";
			}

			if ( $_SESSION['search_contact_type_id'] != "" and $_SESSION['search_contact_type_id'] != "1" ) {
				$search_sql_where .= " and bl.contact_type_id = " . $_SESSION['search_contact_type_id']. "";
			}
			if ( $_SESSION['search_where_clause'] != "" ) {
				$search_sql_where .= " and concat( bl.societe, bl.nom, bl.prenom, bl.adresse, bl.NP,
						bl.ville, bl.canton, bl.pays, bl.tel_prive, bl.tel_professionnel,
						bl.mobile, bl.url, bl.date_de_naissance, bl.capacite, bl.vu_sur,
						bl.remarque, bl.multimedia, bl.a_voir, bl.email ) LIKE '%" . $_SESSION['search_where_clause']. "%'";
			}

			deb_echo ("La search_sql_where : " . $search_sql_where);
		}

		/*********************************
		* Tableau de selection
		**********************************
		/*
		** Comptage des pages
		*/

		/* mise en pages */
		$sql = "SELECT count(*) as tot_rec FROM " . TB . "contacts bl where 1 = 1 "
		. $search_sql_where ;

		$result = $db->query($sql);
		$row = $result->fetchrow(DB_FETCHMODE_ASSOC);
		$tot_rec=$row['tot_rec'];
		$tot_page=ceil($tot_rec/NB_REC_PAGE);

		/*
		** La clause LIMIT
		*/
		$limit_clause = "LIMIT " . (($cur_page - 1) * NB_REC_PAGE ) . ", " . NB_REC_PAGE;
		?>
		<div>
		<center>
		<fieldset>
		<legend>Contacts</legend>

			<?php

			/*
			** URL de filtrage
			*/
			echo $filter_tmp_label . "   ";
			$url_filter=INDEX_FORM . "?adm_action=0&id=" . $service_id . "&sub_id=". $shortname . "&" . $filter_back_url;
			$url_filter_label="<img src=\"" . $filter_img . "\" width=\"16\" height=\"16\" border=\"0\">";
			print_url($url_filter, $url_filter_label);

			/*
			** Affichage de la page courante
			*/
			echo " Page : " . $cur_page . " de " . $tot_page . "   ";

			/*
			** URLs d acces aux pages
			*/
			for ($i = 1; $i <= $tot_page; $i++) {
				$url=INDEX_FORM . "?adm_action=0&adm_id=NA&id=" . $service_id . "&sub_id=". $shortname . "&cur_page=". $i . "&filter=" . $filter;
				if ( $i == $cur_page ) {
				echo "[";
				print_url($url, $i);
				echo "]";
				}else{
				echo " ";
				print_url($url, $i);
				echo " ";
				}
			}
			?>


		<?php

		/* on lance la query */
		$sql = "SELECT "
				. "bl.id"
				. ",bl.societe"
				. ",bl.nom"
				. ",bl.prenom"
				. ",bl.spec_type"
				. ",bl.adresse"
				. ",bl.NP"
				. ",bl.ville"
				. ",bl.canton"
				. ",bl.pays"
				. ",bl.tel_prive"
				. ",bl.tel_professionnel"
				. ",bl.mobile"
				. ",bl.url"
				. ",bl.email"
				. ",ty.nom as type"
				. ",bl.spec_type"
				. ",bl.contact_type_id "
			. " FROM " . TB . "contacts bl, " . TB . "contact_types ty "
			. " WHERE ty.id = bl.contact_type_id "
			. $search_sql_where
			. " ORDER BY bl.nom, bl.prenom, bl.societe "
			. $limit_clause;

		deb_echo ("Les clients query : " . $sql );

		$result = $db->query($sql);
		?>

		<table class="affiche" width="100%"  border="0" summary="Vue courte des contactes">
		  <tr>
			<th scope="col" width="10%">Sociciete</th>
			<th scope="col" width="5%">Nom</th>
			<th scope="col" width="5%">Prenom</th>
			<th scope="col" width="5%">Type</th>
			<th scope="col" width="15%">Adresse</th>
			<th scope="col" width="15%">Mobile</th>
			<th scope="col" width="20%">Tel</th>
			<th scope="col" width="10%">URL</th>
			<th scope="col" width="10%">Email</th>
			<th scope="col" width="5%">Action</th>
		  </tr>

		<?php

     	/* on remplit la table */
	    while ($row = $result->fetchrow(DB_FETCHMODE_ASSOC)) {
			$url_basis= "&adm_id=" . $row['id'] . "&id=" . $service_id . "&sub_id=". $shortname . "&cur_page=". $cur_page . "&filter=" . $filter;
			$url_view = INDEX_FORM . "?adm_action=5" . $url_basis;
			$url_edit = INDEX_FORM . "?adm_action=2" . $url_basis;
			$url_pdf_print = INDEX_FORM . "?adm_action=4" . $url_basis;
			$url_del = INDEX_FORM . "?adm_action=3" . $url_basis;
			?>
			 <tr>
				<td>
					<?php
					print_url_if_not_null($url_view, $row['societe']);
					?>
				</td>
				<td><?php print_url_if_not_null($url_view, $row['nom']); ?></td>
				<td><?php print_url_if_not_null($url_view, $row['prenom']); ?></td>
				<td>
				<?php
					if ( $row['contact_type_id'] == 1 ){
						read_char_from_db($row['spec_type']);
					}else{
						read_char_from_db($row['type']);
					}
				?>
				</td>
				<td><?php read_char_from_db($row['adresse'] . "<br/>". $row['NP'] . " " . $row['ville'] . " " . $row['pays']   ); ?></td>
				<td><?php read_char_from_db($row['mobile']); ?></td>
				<td><?php echo "(prive) " . $row['tel_prive'] . "<br/> (prof) " . $row['tel_professionnel'] ; ?></td>
				<td><?php open_url($row['url'], $row['url']); ?></td>
				<td>
					<?php open_email ($row['email'], $row['email']);?>
				</td>
				<td>
					<?php print_url_if_not_null($url_edit,IMG_CONT_3);?>
					<?print_del_url($url_del,MSG_DEL_QUERY);?>
					<?php print_url_if_not_null($url_pdf_print,IMG_CONT_5);?>

				</td>
		  	</tr>
		<?php
	    }
	    ?>
		</table>
		</fieldset>
		</center>
	    <p>
		<?php
		$url_new=INDEX_FORM . "?adm_action=1&adm_id=NA&id=" . $service_id . "&sub_id=" . $shortname . "&cur_page=". $cur_page . "&filter=" . $filter;
		$url_new_label=MSG_CONT_3;
		print_url($url_new, $url_new_label);
        ?>
		</p>
		</div>

	    <?php
		break;

case 3;   // Mode effacer
		$url_back = INDEX_FORM . "?id=" . $service_id . "&sub_id=" . $shortname . "&cur_page=". $cur_page . "&filter=" . $filter;
		del_record_and_go_back($db,  $service_id, $table_name, $id, $url_back);
	    break;

case 4;   // PrintToPdf

		print_to_pdf($db,  $service_id, $table_name, $id);
	    break;

case 5; // 5 = visialisation

		$sql = "SELECT"
				." bl.societe,"
				." bl.nom,"
				." bl.prenom,"
				." bl.contact_type_id,"
				." ty.nom as type,"
				." bl.spec_type,"
				." bl.contact_genre_id,"
				." ge.nom as genre,"
				." bl.adresse,"
				." bl.NP,"
				." bl.ville,"
				." bl.canton,"
				." bl.pays,"
				." bl.tel_prive,"
				." bl.tel_professionnel,"
				." bl.mobile,"
				." bl.url,"
				." bl.mail_liste_id,"
				." ma.nom as mailing_list,"
				." DATE_FORMAT(bl.date_de_naissance,'%d/%m/%Y'),"
				." bl.capacite,"
				." bl.vu_sur,"
				." bl.remarque,"
				." bl.multimedia,"
				." bl.a_voir,"
				." bl.email"
				." FROM " . TB . "contacts bl,"
				."     " . TB . "contact_types ty,"
				."     " . TB . "contact_genres ge,"
				."     " . TB . "mail_listes ma"
				." WHERE ty.id = bl.contact_type_id"
				." AND   ge.id = bl.contact_genre_id"
				." AND   ma.id = bl.mail_liste_id"
				." AND bl.id=" . $id;

			deb_echo ("La query de visualisation est : " . $sql);

	        /* assignation dans variables session */
	        if (is_array($row = $db->getRow($sql))) {
	            list(
					$societe,
					$nom,
					$prenom,
					$contact_type_id,
					$type,
					$spec_type,
					$contact_genre_id,
					$genre,
					$adresse,
					$NP,
					$ville,
					$canton,
					$pays,
					$tel_prive,
					$tel_professionnel,
					$mobile,
					$url,
					$mail_liste_id,
					$mailing_list,
					$date_de_naissance,
					$capacite,
					$vu_sur,
					$remarque,
					$multimedia,
					$a_voir,
					$email) = $row;
				}
				
		        ?>
				<div class="affiche">
				<center>
				<fieldset style="width:70%";>
				<legend>Contact</legend>

			    <table   border="0">

				<?php
				// on affiche seulement si necessaire
				if ( $societe != "" ){
				?>
				<tr>
				  <th width="25%" scope="row">Societe</th>
				  <td width="75%" style="font-size: larger;"><?php echo $societe;?></td>
				</tr>
			  	<tr>
				  <th width="25%" scope="row">Type</th>
				  <td width="75%"><?php
				  	if ( $contact_type_id == 1 ){
						echo $spec_type;
					}else{
						echo $type;
					}?>
				   </td>
				</tr>
				<?php }
				if ( $nom != "" and $prenom != "") {
				?>
				<tr>
				  <th width="25%" scope="row">Nom</th>
				  <td width="75%" style="font-size: larger;"><?php
				  echo $nom . " " . $prenom ;
				  ?>
				  </td>
				</tr>
				<?php } ?>
				
				<tr>
				  <th width="25%" scope="row">Adresse</th>
				  <td width="75%"><?php echo $adresse ."<br/>" . $NP . " " . $ville;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Canton</th>
				  <td width="75%"><?php echo $canton;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Pays</th>
				  <td width="75%"><?php echo $pays;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Tel. prive</th>
				  <td width="75%"><?php echo $tel_prive;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Tel. Prof.</th>
				  <td width="75%"><?php echo $tel_professionnel;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Mobile</th>
				  <td width="75%"><?php echo $mobile;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">URL</th>
				  <td width="75%"><?php
					open_url ($url, $url);
					?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Mailing</th>
				  <td width="75%"><?php echo $mailing_list;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Date de naissance</th>
				  <td width="75%"><?php echo $date_de_naissance;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Capacite</th>
				  <td width="75%"><?php echo $capacite;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Vu sur...</th>
				  <td width="75%"><?php echo $vu_sur;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Remarque</th>
				  <td width="75%"><?php echo $remarque;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Multimedia</th>
				  <td width="75%"><?php echo $multimedia;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">A voir...</th>
				  <td width="75%"><?php echo $a_voir;?></td>
				</tr>
				<tr>
				  <th width="25%" scope="row">Email</th>
				  <td width="75%"><?php open_email ($email, $email);?></td>
				</tr>
               </table>

			<?php
			$url_basis= "&adm_id=" . $id . "&id=" . $service_id . "&sub_id=". $shortname . "&cur_page=". $cur_page . "&filter=" . $filter;
			$url_edit = INDEX_FORM . "?adm_action=2" . $url_basis;
			$url_print = INDEX_FORM . "?adm_action=4" . $url_basis;
			$url_back = INDEX_FORM . "?id=" . $service_id . $url_basis;
			print_url($url_edit, "Editer");
			echo " ";
			print_url($url_print, "Imprimer");
			echo " ";
			print_url($url_back, "Retours aux " . $titre);
			?>
			</fieldset>
			</center>
			</div>
		<?php
	    break;

case 1 or 2;  // mode ajouter ou editer

	    /* definir la query */
	    $sql = 'select * from ' . $table_name . '
	    where id = "' . $id . '"';

	    /* lancer la query */
	    $res = $db->query($sql);

	    // check des erreurs DB
	    if ( DB::isError( $res = $db->query( $sql ) ) ) {
		    echo MSG_DB_ERR,DB::errorMessage($res), '<br/>';
	    }else{


        /* il s'agit d'un nouveau utilisateur , on essigne les valeurs par defaut */
	        if ($id == "NA"){
				$id = null;
				$societe = "";
				$nom = "votre nom";
				$prenom = "votre prenom";
				$contact_type_id = 1;
				$spec_type = null;
				$contact_genre_id= 1;
				$adresse = null ;
				$NP= null ;
				$ville = null ;
				$canton = null ;
				$pays = null ;
				$tel_prive = null ;
				$tel_professionnel = null ;
				$mobile = null ;
				$url = null ;
				$mail_liste_id = 1;
				$date_de_naissance = null ;
				$capacite = null ;
				$vu_sur = null ;
				$remarque = null ;
				$multimedia = null ;
				$a_voir = null ;
				$email = null ;
	        }else{

				/* assignation dans variables session */
				if (is_array($row = $db->getRow($sql))) {
					list(
						$id,
						$societe,
						$nom,
						$prenom,
						$contact_type_id,
						$spec_type,
						$contact_genre_id,
						$adresse,
						$NP,
						$ville,
						$canton,
						$pays,
						$tel_prive,
						$tel_professionnel,
						$mobile,
						$url,
						$mail_liste_id,
						$date_de_naissance,
						$capacite,
						$vu_sur,
						$remarque,
						$multimedia,
						$a_voir,
						$email
						) = $row;
				}}

	
	        /*
	        ** creation du formulaire a l'aide des fonction de HTML_QuickForm
	        */
			/* instanciation de la classe */
	        $form = new HTML_QuickForm('frm' . $table_name, 'post',  INDEX_FORM . '?adm_action=' . $action . '&adm_id=' . $id . '&id=' . $service_id . '&sub_id=' . $shortname . '&filter=' . $filter);
			$form->addElement('hidden', 'id', 'Id', array('value' => $id));

			/* les champs */
			$form->addElement('text', 'societe', 'Societe', array('class' => formInputField, 'value' => $societe , 'size' => 60, 'maxlength' => 100));

		    $res2 = $db->getAssoc('select id, nom from ' . TB . 'contact_types order by nom');
	        $form->addElement('select', 'contact_type_id', 'Type', $res2, 'id=id');
  			$form->setDefaults(array('contact_type_id' => $contact_type_id));
			$form->addElement('text', 'spec_type', 'si pas dans la liste', array('class' => formInputField,'value' => $spec_type , 'size' => 30, 'maxlength' => 30));

			$res1 = $db->getAssoc('select id, nom from ' . TB . 'contact_genres order by nom');
	        $form->addElement('select', 'contact_genre_id', 'Genre', $res1, 'id=id');
	        $form->setDefaults(array('contact_genre_id' => $contact_genre_id));

	        $form->addElement('text', 'nom', 'Nom', array('class' => formInputField,'value' => $nom, 'size' => 60, 'maxlength' => 100));
	        $form->addElement('text', 'prenom', 'Prenom', array('class' => formInputField,'value' => $prenom, 'size' => 60, 'maxlength' => 100));

		    $form->addElement('textarea', 'adresse', 'Adresse', array("class"=>"formInputField",
																	   "rows"=>"3",
																	   "cols"=>"50",
																	   "maxlength"=>"100",
																	   "id" => "adresse"));
			$form->setDefaults(array('adresse' => $adresse));

	        $form->addElement('text', 'NP', 'NP', array('class' => formInputField,'value' => $NP, 'size' => 6, 'maxlength' => 6));
	        $form->addElement('text', 'ville', 'Ville', array('class' => formInputField,'value' => $ville, 'size' => 50, 'maxlength' => 50));
	        $form->addElement('text', 'canton', 'Canton / Region', array('class' => formInputField,'value' => $canton, 'size' => 50, 'maxlength' => 50));
	        $form->addElement('text', 'pays', 'Pays', array('class' => formInputField,'value' => $pays, 'size' => 50, 'maxlength' => 50));

	        $form->addElement('text', 'tel_prive', 'Tel. Prive', array('class' => formInputField,'value' => $tel_prive, 'size' => 50, 'maxlength' => 50));
	        $form->addElement('text', 'tel_professionnel', 'Tel. Prof.', array('class' => formInputField,'value' => $tel_professionnel, 'size' => 50, 'maxlength' => 50));
	        $form->addElement('text', 'mobile', 'Mobile/Natel', array('class' => formInputField,'value' => $mobile, 'size' => 50, 'maxlength' => 50));

             $options = array(
                'language'  => 'fr',
                'format'    => 'dMY',
                'minYear'   => 1950,
                'maxYear'   => 2006
                );

            $form->addElement('date', 'date_de_naissance', 'Date de naissance', $options);
	        $form->setDefaults(array('date_de_naissance' => $date_de_naissance));
			$form->addElement('text', 'email', 'Email', array('class' => formInputField,'value' => $email,'size' => 50, 'maxlength' => 50));
			$form->addElement('text', 'url', 'URL', array('class' => formInputField,'value' => $url,'size' => 50, 'maxlength' => 50));

	        $res3 = $db->getAssoc('select id, nom from ' . TB . 'mail_listes order by nom');
	        $form->addElement('select', 'mail_liste_id', 'Type de mail liste', $res3, 'id=id');
	        $form->setDefaults(array('mail_liste_id' => $mail_liste_id));

	        $form->addElement('text', 'capacite', 'Capacite', array('class' => formInputField,'value' => $capacite, 'size' => 50, 'maxlength' => 50));
	        $form->addElement('text', 'vu_sur', 'Vu sur', array('class' => formInputField,'value' => $vu_sur, 'size' => 50, 'maxlength' => 50));

		    $form->addElement('textarea', 'remarque', 'Remarque', array("class"=>"warn",
																	   "rows"=>"3",
																	   "cols"=>"50",
																	   "maxlength"=>"255",
																	   "id" => "remarque"));
			$form->setDefaults(array('remarque' => $remarque));

			$form->addElement('textarea', 'multimedia', 'Multimedia', array("class"=>"warn",
																		   "rows"=>"3",
																		   "cols"=>"50",
																		   "maxlength"=>"255",
																		   "id" => "multimedia"));
			$form->setDefaults(array('multimedia' => $multimedia));

			$form->addElement('textarea', 'a_voir', 'A voir', array("class"=>"warn",
																   "rows"=>"3",
																   "cols"=>"50",
																   "maxlength"=>"255",
																   "id" => "a_voir"));
			$form->setDefaults(array('a_voir' => $a_voir));

			/* les rules */
//	        $form->addRule('nom', 'Vous devez saisir nom', 'required', '', 'client');
//	        $form->addRule('prenom', 'Vous devez saisir un prenom', 'required', '', 'client');
//	        $form->addRule('email', 'Vous devez saisir votre adresse Email', 'required', '', 'client');
//	        $form->addRule('email', 'Ce champ doit &ecirc;tre un email valide', 'email', '', 'email');
	        $form->addRule('remarque', 'Le nombre maximum de charateres est de 255 !!', 'maxlength', 255, 'remarque');
			$form->addRule('multimedia', 'Le nombre maximum de charateres est de 255 !!', 'maxlength', 255, 'multimedia');
			$form->addRule('a_voir', 'Le nombre mximum de charateres est de 255 !!', 'maxlength', 255, 'a_voir');

	        $form->setRequiredNote('<span style="color: #ff0000">*</span> = champs obligatoires');
	        $form->setJsWarnings('Erreur de saisie','Veuillez corriger');

	        $form->addElement('submit', 'bouton_effacer', 'Envoyer', array('class' => formInputField));

	        /* c'est quand l'utlisateur presse le bouton .... */
	        if ($form->validate()) {  //form

				/* dates */
                $insc_ar = $form->exportValue('date_de_naissance');
                $insc_str = $insc_ar["Y"] . "-" . $insc_ar["M"] . "-" . $insc_ar["d"] . " " . $insc_ar["h"] . ":" . $insc_ar["m"];

	            /* on recupere les valeurs du formulaire */
	            $fields_values = array(
				'id' => $form->exportValue('id'),
				'societe' => $form->exportValue('societe'),
				'nom' => $form->exportValue('nom'),
				'prenom' => $form->exportValue('prenom'),
				'contact_type_id' => $form->exportValue('contact_type_id'),
				'spec_type' => $form->exportValue('spec_type'),
				'contact_genre_id' => $form->exportValue('contact_genre_id'),
				'adresse' => $form->exportValue('adresse'),
				'NP' => $form->exportValue('NP'),
				'ville' => $form->exportValue('ville'),
				'canton' => $form->exportValue('canton'),
				'pays' => $form->exportValue('pays'),
				'tel_prive' => $form->exportValue('tel_prive'),
				'tel_professionnel' => $form->exportValue('tel_professionnel'),
				'mobile' => $form->exportValue('mobile'),
				'url' => $form->exportValue('url'),
				'mail_liste_id' => $form->exportValue('mail_liste_id'),
				'date_de_naissance' => $insc_str,
				'capacite' => $form->exportValue('capacite'),
				'vu_sur' => $form->exportValue('vu_sur'),
				'remarque' => $form->exportValue('remarque'),
				'multimedia' => $form->exportValue('multimedia'),
				'a_voir' => $form->exportValue('a_voir'),
				'email' => $form->exportValue('email'));

	            /* test pour savoir si on fait un update ou un insert */
	            if ($action == 1 ){
		            $resins = $db->autoExecute($table_name, $fields_values, DB_AUTOQUERY_INSERT);
	            }else{
		            $resins = $db->autoExecute($table_name, $fields_values, DB_AUTOQUERY_UPDATE, "id = $id");
	            }

	            /* check des erreurs */
	            if (DB::isError($resins)) {
					/* utilisation d'une fonction de print de message d'erreur */
					print_insupd_err(MSG_INSUPG_ERR, $resins->getMessage());
					form_display($form, "Edition d'un contact", "forms", "100%");
	            }else{
					$url_back=INDEX_FORM . "?id=" . $service_id . "&sub_id=" . $shortname . "&cur_page=". $cur_page . "&filter=" . $filter; ;
					go_back($url_back, MSG_INSUPD_RECORD,1);
	            }
	        }else{
				form_display($form, "Edition d'un contact", "forms", "80%");

				$url_back=INDEX_FORM . "?id=" . $service_id . "&sub_id=" . $shortname . "&cur_page=". $cur_page . "&filter=" . $filter; ;
				print_url($url_back, "Retours aux " . $titre);
			 } //form
	    } //erreur base de donnees
	    break;

	} //switch
  } //if check des droits
  else
  {
	print_err_right_on_page(INDEX_FORM);
  }
}

?>
